package org.momo.rpc.loadbalance.impl;

import org.momo.rpc.loadbalance.LoadBalancer;
import org.momo.rpc.protocol.RpcRequest;
import org.momo.rpc.provider.model.ProviderRegistryInfo;

import java.util.List;
import java.util.Random;

public class RandomLoadBalancer implements LoadBalancer {
    private final Random random = new Random();

    @Override
    public ProviderRegistryInfo loadBalance(RpcRequest request, List<ProviderRegistryInfo> possibleServiceList) {
        int size = possibleServiceList.size();
        return possibleServiceList.get(random.nextInt(size));
    }

}
